#! /bin/bash
SQOOP_HOME=/usr/bin/sqoop

#上个月1日
if [[ $1 == "" ]]
then
    Last_Month_DATE=$(date -d "$(date +%Y%m)01 last month" +%Y-%m-01)
else
    Last_Month_DATE=$1
fi

DATESTR=`date -d "-1 day" +%Y`

mysql -uroot -p123456 -h192.168.10.150 -P3306 -e "delete from scrm_bi.itcast_clue where yearinfo <= '${Last_Month_DATE:0:4}'"

wait

$SQOOP_HOME export \
--connect "jdbc:mysql://192.168.10.150:3306/scrm_bi?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password '123456' \
--table itcast_clue \
--hcatalog-database itcast_dws \
--hcatalog-table itcast_clue_dws \
--hcatalog-partition-keys yearinfo \
--hcatalog-partition-values ${DATESTR} \
-m 10

#! /bin/bash
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]]
then
   TD_DATE=`date -d '-1 day' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

TD_YEAR=$(date -d "$TD_DATE" +%Y)

mysql -uroot -p123456 -h192.168.10.150 -P3306 -e "delete from scrm_bi.itcast_visit where yearinfo='$TD_YEAR';"

wait

$SQOOP_HOME export \
--connect "jdbc:mysql://192.168.10.150:3306/scrm_bi?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password '123456' \
--table itcast_visit \
--hcatalog-database itcast_dws \
--hcatalog-table visit_dws \
--hcatalog-partition-keys yearinfo \
--hcatalog-partition-values $TD_YEAR \
-m 10